namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update117 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.SysTaskHistoryMessage", "TaskHistoryId", "dbo.SysTaskHistory");
            DropForeignKey("dbo.SysTaskHistoryNotification", "EmpId", "dbo.hrm_ps_employees");
            DropForeignKey("dbo.SysTaskHistoryNotification", "TaskId", "dbo.SysTask");
            DropIndex("dbo.SysTaskHistoryMessage", new[] { "TaskHistoryId" });
            DropIndex("dbo.SysTaskHistoryNotification", new[] { "EmpId" });
            DropIndex("dbo.SysTaskHistoryNotification", new[] { "TaskId" });
            AddColumn("dbo.SysTask", "IsInRequiringSendBack", c => c.Boolean(nullable: false));
            AddColumn("dbo.SysTaskHistory", "SendBackOkBy", c => c.Int());
            AddColumn("dbo.SysTaskHistory", "SendBackOkByPosName", c => c.String());
            AddColumn("dbo.SysTaskHistory", "SendBackOkByFullName", c => c.String());
            AddColumn("dbo.SysTaskHistory", "SendBackOkWhen", c => c.DateTime());
            DropTable("dbo.SysTaskHistoryMessage");
            DropTable("dbo.SysTaskHistoryNotification");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.SysTaskHistoryNotification",
                c => new
                    {
                        TaskHistoryNotificationId = c.Int(nullable: false, identity: true),
                        EmpId = c.Int(),
                        TaskId = c.Int(),
                        Notified = c.Boolean(nullable: false),
                        Read = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.TaskHistoryNotificationId);
            
            CreateTable(
                "dbo.SysTaskHistoryMessage",
                c => new
                    {
                        TaskHistoryMessageId = c.Int(nullable: false, identity: true),
                        TaskHistoryId = c.Int(nullable: false),
                        MessageText = c.String(),
                        Completed = c.Boolean(nullable: false),
                        AllowEdit = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.TaskHistoryMessageId);
            
            DropColumn("dbo.SysTaskHistory", "SendBackOkWhen");
            DropColumn("dbo.SysTaskHistory", "SendBackOkByFullName");
            DropColumn("dbo.SysTaskHistory", "SendBackOkByPosName");
            DropColumn("dbo.SysTaskHistory", "SendBackOkBy");
            DropColumn("dbo.SysTask", "IsInRequiringSendBack");
            CreateIndex("dbo.SysTaskHistoryNotification", "TaskId");
            CreateIndex("dbo.SysTaskHistoryNotification", "EmpId");
            CreateIndex("dbo.SysTaskHistoryMessage", "TaskHistoryId");
            AddForeignKey("dbo.SysTaskHistoryNotification", "TaskId", "dbo.SysTask", "TaskId");
            AddForeignKey("dbo.SysTaskHistoryNotification", "EmpId", "dbo.hrm_ps_employees", "emp_seq");
            AddForeignKey("dbo.SysTaskHistoryMessage", "TaskHistoryId", "dbo.SysTaskHistory", "TaskHistoryId", cascadeDelete: true);
        }
    }
}
